//---------------------------------------------------------------------------


#pragma hdrstop

#include "Pen.h"
#include <math>

//---------------------------------------------------------------------------

#pragma package(smart_init)

Pen::Pen(Scene *scene) {
        this->scene = scene;
        position = *new GLPoint();
        direction = 0.0f;
};

Pen::Pen(Scene *scene, GLPoint position, float direction) {
        this->scene = scene;
        this->position = position;
        this->direction = direction;
};

void Pen::move(float x,  bool penDown) {
        position.setX(position.getX() + x*cos(direction));
        position.setY(position.getY() + x*sin(direction));
        if (penDown)
     scene->addPoint(position);
};



void Pen::moveTo(float x, float y, bool penDown) {
        position.setX(x);
        position.setY(y);
        if (penDown)
                scene->addPoint(*new GLPoint(x,y));
};

void Pen::avanza ( float distance, bool penDown )  {
        float dirRads=direction*M_PI/180.0;
        float x=position.getX() + distance*cos(dirRads);
        float y=position.getY() + distance*sin(dirRads);
        position.setX(x);
        position.setY(y);
        if (penDown) {
                scene->addPoint(*new GLPoint(x, y));
        }

};

void Pen::moveTo(GLPoint p, bool penDown) {
        position.setX(p.getX());
        position.setY(p.getY());
        if (penDown)
                scene->addPoint(p);
};

void Pen::turn(float angle) {
        direction += angle;
};

void Pen::turnTo(float angle){
        direction = angle;
};

GLPoint Pen::getPosition() {
        return position;
};

void Pen::setPosition   ( GLPoint position ) {
  this->position = position ;
};

void Pen::setDirection   ( float direction ) {
  this->direction = direction;
};

void Pen::torn( float angle ){
  this->direction = direction + angle;
};
